package com.example.springbootbase.service;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Service
public class UserService  implements BeanNameAware, BeanFactoryAware, InitializingBean, ApplicationContextAware {

    public UserService() {
        System.out.println("UserService constructor");
    }

    public void addUser(String userName){
        System.out.println("add user:"+userName);
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("set bean name:"+name);
    }

    @PostConstruct
    public void init(){
        System.out.println("post construct");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
//        System.out.println(beanFactory);
    }
    @PreDestroy
    public void initPreDestroy(){
        System.out.println("pre destroy");
    }


    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("after properties set");
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println(applicationContext);
    }
}
